﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Networking
{
    /// <summary>
    /// Packet of type PacketSecurityResponse, the response of PacketSecurity containing the accepted security type
    /// </summary>
    public class SecurityResponsePacket : Packet
    {

        /// <summary>
        /// The accepted security type
        /// </summary>
        public SecurityType AcceptedSecurity { get; private set; }

        /// <summary>
        /// Creates a new instance of PacketSecurityResponse with the accepted security type
        /// </summary>
        /// <param name="AcceptedSecurity"></param>
        public SecurityResponsePacket(SecurityType AcceptedSecurity)
            : base(PacketType.SecurityResponse)
        {
            this.AcceptedSecurity = AcceptedSecurity;
        }

        /// <summary>
        /// Creates a new instance of SecurityResponsePacket extracting all the parameters from the byte buffer
        /// </summary>
        /// <param name="buffer">The byte buffer containing the packet data</param>
        public SecurityResponsePacket(byte[] buffer) 
            : base(PacketType.SecurityResponse, buffer)
        {
            //
        }

        /// <summary>
        /// Serializes the packet in order to send it
        /// </summary>
        /// <returns>The bytes of the packet</returns>
        public override byte[] Serialize()
        {
            //return new byte[0] { (byte)AcceptedSecurity }; //BitConverter.GetBytes((Int64)AcceptedSecurity);
            return new byte[] { (byte)AcceptedSecurity };
            //cancellare questa merdina
        }


        /// <summary>
        /// Loads a packet from a byte buffer
        /// </summary>
        /// <param name="buffer">The data buffer</param>
        public override void Load(byte[] buffer)
        {
            if (buffer.Length != 1) throw new BufferSizeMismatchException(1);

            AcceptedSecurity = (SecurityType)AcceptedSecurity;

        }
    }
}
